import { parse } from 'url';
import { TableListItem, TableListParams } from './data';

function getRechargeMoney(
  req: { url: any },
  res: {
    json: (
      arg0: {
        body: {
          list: TableListItem[];
          count: number,
        }
      },
    ) => void;
  },
  u: any,
) {
  let url = u;
  if (!url || Object.prototype.toString.call(url) !== '[object String]') {
    // eslint-disable-next-line prefer-destructuring
    url = req.url;
  }

  const params = (parse(url, true).query as unknown) as TableListParams;

  const dataSource: TableListItem[] = [];

  for (let i = (params.pageNum - 1) * 10; i < 10 * params.pageNum; i += 1) {
    dataSource.push({
      id: i + 1,
      consume: 757,
      consume_warn_amount: 0,
      create_time: '2018-07-19 15:19:50',
      fcs_id: 19,
      fcs_level: 1,
      income: 2107,
      name: '测试lin23',
      parent_name: '中科富创',
      phone: '15801107600',
      total_income: 0,
      total_withdraw: 0,
      update_time: '2019-05-24 14:44:44',
    });
  }

  const result = {
    code: 0,
    body: {
      list: dataSource,
      count: 30,
    },
  };

  return res.json(result);
}

export default {
  'GET /account/recharge/query': getRechargeMoney,
};
